﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EqRepair.Code.Classes;
using EqRepair.Code.Data;

namespace EqRepair.Web
{
	public partial class ReportToRep : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
		{
			
		}

		protected void Button1_Click(object sender, EventArgs e)
		{
			using (var db = new DataClasses2DataContext())
			{
				AccessData.CreateAutoReq();
				if (DropDownList1.SelectedItem!= null)
				{
					int i = 0;
					var Join =
						from lnk in db.EquipmentInOrganizations
						//join eq in db.Equipments on AccessData.GetIDFullParent(lnk) equals eq.Id
						where
							(lnk.NextRepairDate.Value.Year == DateTime.Now.Year &&
							 lnk.OrganizationId == Int32.Parse(DropDownList1.SelectedValue))
						select new
						       	{
						       		//пп = 1,
						       		r1 = AccessData.GetIDFullParent(lnk),
						       		r2 = lnk.Equipment.Name,
						       		r3 = lnk.NextRepairDate,
						       		r4 = lnk.Equipment.LifeTime,
						       		r5 = lnk.Equipment.RepairTime,
						       		r6 = lnk.Equipment.RepairCost
						       	};
					GridView1.DataSource = Join;
					GridView1.DataBind();
					double t = 0, m = 0;
					foreach (GridViewRow row in GridView1.Rows)
					{
						t += double.Parse(row.Cells[4].Text);
						m += double.Parse(row.Cells[5].Text);
					}



					sum.Text = "Итого трудозатрат (чел./час): " + t + ". Стоимость работ: " + m;
				}
			}
		}
	}
}
